<template>
  <div>
    <div>
      <div style="display: flex; justify-content: space-between">
        <div>
          <el-input
            placeholder="请输入工号进行搜索，可以直接回车搜索..."
            prefix-icon="el-icon-search"
            clearable
            @clear="initRecords"
            style="width: 350px; margin-right: 10px"
            v-model="keyword"
            @keydown.enter.native="initRecords"
          ></el-input>
          <el-button
            icon="el-icon-search"
            type="primary"
            @click="initRecords"
          >
            搜索
          </el-button>
        </div>
      </div>
    </div>
    <div style="margin-top: 10px">
      <el-table
        :data="records"
        stripe
        border
        v-loading="loading"
        element-loading-text="正在加载..."
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.8)"
        style="width: 100%"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column
          prop="workId"
          fixed
          align="left"
          label="工号"
          width="150"
        >
        </el-table-column>
        <el-table-column
          prop="clockInTime"
          label="上班打卡时间"
          align="left"
          width="230"
        >
        </el-table-column>
        <el-table-column
          prop="clockInAddr"
          label="上班打卡地址"
          align="left"
          width="260"
        >
        </el-table-column>
        <el-table-column
          prop="clockOutTime"
          label="下班打卡时间"
          align="left"
          width="230"
        >
        </el-table-column>
        <el-table-column
          prop="clockOutAddr"
          label="下班打卡地址"
          align="left"
          width="260"
        >
        </el-table-column>

        <el-table-column fixed="right" width="100" label="操作">
          <template slot-scope="scope">
            <!-- <el-button
              @click="showEditEmpView(scope.row)"
              style="padding: 3px"
              size="mini"
              >编辑</el-button
            > -->
            <!-- <el-button style="padding: 3px" size="mini" type="primary">查看详细资料</el-button> -->
            <el-button
              @click="deleteRecord(scope.row)"
              style="padding: 3px"
              size="mini"
              type="danger"
              >删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div style="display: flex; justify-content: flex-end">
        <el-pagination
          background
          @current-change="currentChange"
          @size-change="sizeChange"
          layout="sizes, prev, pager, next, jumper, ->, total, slot"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "EmpClock",
  data() {
    return {
      title: "",
      records: [],
      loading: false,
      total: 0,
      page: 1,
      keyword: "",
      size: 10,
    };
  },
  mounted() {
    this.initRecords();
  },
  methods: {
    deleteRecord(data) {
      this.$confirm(
        "此操作将永久删除【" + data.workId + "】, 是否继续?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          this.deleteRequest("/employee/clock/" + data.id).then((resp) => {
            if (resp) {
              this.initRecords();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    sizeChange(currentSize) {
      this.size = currentSize;
      this.initRecords();
    },
    currentChange(currentPage) {
      this.page = currentPage;
      this.initRecords();
    },
    initRecords() {
      this.loading = true;
      let url = "/employee/clock/?page=" + this.page + "&size=" + this.size;
      url += "&workId=" + this.keyword;
      this.getRequest(url).then((resp) => {
        this.loading = false;
        if (resp) {
          this.records = resp.data;
          this.total = resp.total;
        }
      });
    },
  },
};
</script>

<style>
/* 可以设置不同的进入和离开动画 */
/* 设置持续时间和动画函数 */
.slide-fade-enter-active {
  transition: all 0.8s ease;
}

.slide-fade-leave-active {
  transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
}

.slide-fade-enter, .slide-fade-leave-to
        /* .slide-fade-leave-active for below version 2.1.8 */ {
  transform: translateX(10px);
  opacity: 0;
}
</style>
